package com.jrx.anytxn.feign.common;

import com.jrx.anytxn.feign.gateway.bean.ApiResponse;
import com.jrx.anytxn.feign.gateway.bean.BaseApiResponse;

/**
 * @program: anytxn-cf-transaction
 * @description:
 * @author: xiaoyu.jing
 * @date: 2020-05-12 10:11
 **/
public interface GateWayPredicate<T extends BaseApiResponse> {

    ApiResponse<T> apply() throws Exception;

    default T getRes(GateWayPredicate predicate) throws Exception {

        ApiResponse<T> response = predicate.apply();
        if(null == response){
            return null;
        }
        if (1000 != response.getCode() ) {
            return null;
        }
        if(null == response.getData()){
            return null;
        }
        if(!"S".equals(response.getData().getDealState())){
            return null;
        }
        return  response.getData();
    }
}